//
//  FindingManager.m
//  OwnerNews
//
//  Created by lanou3g on 15/8/28.
//  Copyright (c) 2015年 Drawzyn. All rights reserved.
//

#import "FindingManager.h"
#import "AFNetworking.h"
#import "FindModel.h"
#import "FindTopImage.h"
#import "FindBtnMessage.h"

#define FINDURL @"http://c.m.163.com/nc/topicset/uc/api/discovery/indexV52"


@implementation FindingManager
static FindingManager * s_defaultManager = nil;

+ (FindingManager *)defaultManager {
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        s_defaultManager = [self new];
    });
    
    return s_defaultManager;
}


- (void)GetMyDataAndLoadMyTableView:(void(^)())Complete {

    AFHTTPRequestOperationManager *findManager = [AFHTTPRequestOperationManager new];
 
    __weak FindingManager *weakSelf = self;
    [findManager GET:FINDURL parameters:NULL success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        
         weakSelf.FindBodyArray = [NSMutableArray new];
         weakSelf.FindMidArray = [NSMutableArray new];
        weakSelf.FindTopArray = [NSMutableArray new];
        weakSelf.MessAgeArray = [NSMutableArray new];
        
        NSArray *array = responseObject[@"stream"];
        for (NSDictionary *dict in array) {
            FindModel *find = [FindModel new];
            [find setValuesForKeysWithDictionary:dict];
            [weakSelf.FindBodyArray addObject:find];
           // NSLog(@"%@",_FindBodyArray);
        }
    
        NSArray *BtnArray = responseObject[@"recommend"];
        for (NSDictionary *Bdict in BtnArray) {
           
            FindBtnMessage *fb = [FindBtnMessage new];
            [fb setValuesForKeysWithDictionary:Bdict];
            [weakSelf.FindMidArray addObject:fb];
            
        }
       
        NSArray *BtnArrays = responseObject[@"banner"];
        for (NSDictionary *Bdicts in BtnArrays) {
            
            FindTopImage *fbs = [FindTopImage new];
            [fbs setValuesForKeysWithDictionary:Bdicts];
            [weakSelf.FindTopArray addObject:fbs];
        }
        [weakSelf.MessAgeArray addObject:weakSelf.FindBodyArray];
        [weakSelf.MessAgeArray addObject:weakSelf.FindMidArray];
       
        
        if (Complete) {
            Complete();
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
    
    
    
    
    
}






@end
